//
//  Button.swift
//  iOSProjectExtensionSwift
//
//  Created by Apple on 2020/1/13.
//  Copyright © 2020 lidianchao. All rights reserved.
//

import UIKit
extension UIButton {
    ///  创建图片button
    /// - Parameters:
    ///   - frame: 位置
    ///   - normal: 正常状况下的图片
    ///   - selectImage: 选中的图片
    ///   - target: self
    ///   - action: 方法
    static func createButtonWithFrame(frame:CGRect, normal:UIImage, selectImage:UIImage, target:AnyObject?,action:Selector) -> UIButton {
        let button = UIButton(frame: frame);
        button.setImage(normal, for: .normal);
        button.setImage(selectImage, for: .selected);
        button.addTarget(target, action: action, for: .touchUpInside);
        button.clipsToBounds = true;
        button.layer.cornerRadius = 2;
        return button;
    }
    /// 创建button
    /// - Parameters:
    ///   - title: 标题
    ///   - frame: 位置
    ///   - target: self
    ///   - action: 方法
    ///   - font: 字体
    ///   - board: 是否加粗
    ///   - textColor: 字体颜色
    static func createButtonWithTitle(title:String, frame:CGRect,target:AnyObject,action:Selector,font:CGFloat, board:Bool, textColor:UIColor) ->UIButton{
        
        let button = UIButton(frame: frame);
        button.setTitle(title, for: .normal);
        button.backgroundColor = UIColor.clear;
        button.setTitleColor(textColor, for: .normal);
        button.setTitleColor(UIColor(white: 1, alpha: 0.4), for: .disabled);
        button.titleLabel?.font = UIFont(name: board ? kFontNameBold() : kFontNameLight(), size: font);
        button.addTarget(target, action: action, for: .touchUpInside);
        return button;
    }
    static func createButtonWithTitle(title:String, frame:CGRect,target:AnyObject,action:Selector,font:CGFloat, textColor:UIColor) ->UIButton {
        let btn = createButtonWithTitle(title: title, frame: frame, target: target, action: action, font: font, board: false, textColor: textColor);
        return btn;
    }
    static func createButtonWithTitle(title:String, frame:CGRect,target:AnyObject,action:Selector,font:CGFloat) ->UIButton {
        return createButtonWithTitle(title: title, frame: frame, target: target, action: action, font: font, board: false,textColor: UIColor.white);
    }
    //添加圆角
    func addCornerRadius(radius:CGFloat,borderWidth:CGFloat,borderColor:UIColor) {
        self.layer.cornerRadius = radius
        self.layer.borderWidth = borderWidth
        self.layer.borderColor = borderColor.cgColor
        self.clipsToBounds = true
    }
}
